{include file="public/head"/}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">字段{if $action=='edit'}修改{else /}添加{/if}</div>
                <div class="layui-card-body" pad15>
                    <div class="layui-form" wid100 lay-filter="form">

                        <div class="layui-form-item">
                            <label class="layui-form-label">所属分组</label>
                            <div class="layui-input-inline">
                                <select id="group_id" name="group_id" lay-verify="required">
                                    <option value='' >请选择分组</option>
                                    {volist name="systemGroup" id="vo"}
                                    <option  value="{$vo.id}">{$vo.name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">字段类型</label>
                            <div class="layui-input-inline">
                                <select id="type" name="type" lay-filter="type" lay-verify="required">
                                    <option value='' >请选择字段类型</option>
                                    {volist name="fildType" id="vo"}
                                    <option value="{$key}">{$vo}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">字段名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="field" lay-verify="required" placeholder="必填：字段名" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">别名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="name" lay-verify="required" placeholder="必填：别名" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">提示</label>
                            <div class="layui-input-inline">
                                <input type="text" name="tips" placeholder="请输入提示信息" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">系统设置中表单字段提示语</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">表单元素</label>
                            <div class="layui-input-block">
                                <input type="radio" name="display" value="1" title="整行">
                                <input type="radio" name="display" value="0" title="内联">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">必填</label>
                            <div class="layui-input-block">
                                <input type="radio" name="required" value="1" title="是">
                                <input type="radio" name="required" value="0" title="否">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-block">
                                <input type="radio" name="status" value="1" title="启用">
                                <input type="radio" name="status" value="0" title="禁用">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">排序</label>
                            <div class="layui-input-inline">
                                <input type="text" name="sort" value="" placeholder="请输入排序" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">字段设置</label>
                            <div class="layui-input-block">
                                <div class="layui-col-lg12" id="field_setup">

                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                {if $info}
                                <input type="hidden" name="id" value="">
                                {/if}
                                <button class="layui-btn" lay-submit lay-filter="{if $action=='edit'}edit-btn{else /}add-btn{/if}">确认保存</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/foot"/}
<script>
    layui.config({
        base: '__LAYADMIN__/',version: true
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','system_field','form'],function(){
        var $ = layui.$,form = layui.form;
        form.val("form", {$info|raw})

        {if $info}
        var type = '{$info.type}';
        var name = '{$info.field}';
        var url = "{:url('fieldType')}?type=" + type + "&name=" + name;
        field_setting(type, url);
        {/if}
        form.on('select(type)', function(type){
            var typeVal = type.value;
            var url = "{:url('fieldType')}?type=" + typeVal;
            field_setting(type, url);
        });
        function field_setting(type,url) {
            $.ajax({
                type: "POST",
                url: url,
                beforeSend:function(){
                    $('#field_setup').html('<i class="fa fa-spinner fa-spin fa-fw"></i>');
                    form.render()
                },
                success: function(msg){
                    $('#field_setup').html(msg);
                    form.render()
                },
                complete:function(){
                },
                error:function(){
                }
            });
        }
    });
</script>
</body>
</html>